//
//  DemoViewController.m
//  EFBFrameworkProject
//
//  Created by 徐 洋 on 13-10-24.
//  Copyright (c) 2013年 ADCC. All rights reserved.
//

#import <UIApplication+EFB.h>
#import <EFBAccessoryBar.h>
#import <EFBTitleBar.h>

#import "DemoViewController.h"


@interface DemoViewController ()

@property (retain, nonatomic) EFBTitleBar * titleBar;

@end

@implementation DemoViewController

- (void)mainMenuWillAppear
{
    NSLog(@"mainMenuWillAppear");
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    _titleBar = [[EFBTitleBar alloc] initWithFrame:CGRectZero];
    [_titleBar placeTitleBarToView:self.view];
    _titleBar.titleLabel.text = self.title;
    
    UILabel * titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, 5, 200, 32)] autorelease];
    titleLabel.text = self.title;
    [self.view addSubview:titleLabel];
    titleLabel.textColor = [UIColor blackColor];
    
    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)-207, 5, 200, 32)] autorelease];
    titleLabel.text = self.title;
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
    titleLabel.textColor = [UIColor blackColor];
    [self.view addSubview:titleLabel];
    
    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(CGRectGetWidth(self.view.bounds)-207, CGRectGetHeight(self.view.frame)-37-64, 200, 32)] autorelease];
    titleLabel.text = self.title;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin;
    [self.view addSubview:titleLabel];
    
    titleLabel = [[[UILabel alloc] initWithFrame:CGRectMake(5, CGRectGetHeight(self.view.bounds)-37-64, 200, 32)] autorelease];
    titleLabel.text = self.title;
    titleLabel.textColor = [UIColor blackColor];
    titleLabel.autoresizingMask = UIViewAutoresizingFlexibleTopMargin;
    [self.view addSubview:titleLabel];
        
    UIButton * fullscreenBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    fullscreenBtn.frame = CGRectMake(100,100, 200,50);
    [fullscreenBtn setTitle:self.title forState:UIControlStateNormal];
    [fullscreenBtn addTarget:self action:@selector(fullScreenTapped:) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:fullscreenBtn];
    
    BOOL nightMode = [[UIApplication sharedApplication] nightlyMode];
    NSLog(@"View Loaded with nightly mode : %d", nightMode);
    
    self.view.backgroundColor = nightMode ? [UIColor blackColor] : [UIColor whiteColor];
    
    EFBAccessoryBarItem * item1 = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-lock" target:self action:@selector(onLockTapped:)];
    EFBAccessoryBarItem * item2 = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-lock" target:self action:@selector(onLockTapped:)];
    EFBAccessoryBarItem * item3 = [[EFBAccessoryBarItem alloc] initWithStyleClass:@"accessory-lock" target:self action:@selector(onLockTapped:)];
    
    item3.selected = YES;
    
    self.accessoryItems = @[item1, item2, item3];
    
    [self didFinishLoadView];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    NSLog(@"%@ viewWillAppear", self.title);
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    NSLog(@"%@ viewDidAppear", self.title);
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)fullScreenTapped:(id)sender
{
    self.fullScreenMode = !self.fullScreenMode;
}

- (void)efbNightModeChanged:(BOOL)enabled
{
    self.view.backgroundColor = enabled ? [UIColor blackColor] : [UIColor whiteColor];
}

- (void)onLockTapped:(id)sender
{
    [self lockScreen];
}

@end
